package pri.ydy.eduService.controller.front;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import pri.ydy.commonUtils.R;
import pri.ydy.eduService.entity.EduCourse;
import pri.ydy.eduService.entity.EduTeacher;
import pri.ydy.eduService.service.EduCourseService;
import pri.ydy.eduService.service.EduTeacherService;

import java.util.List;

/**
 * @author YeDongYong
 * @date 2020/12/12 - 14:25 处理前台banner
 */
@RestController
@RequestMapping("/eduservice/indexfront")
public class IndexFrontController {

    @Autowired
    private EduCourseService courseService;

    @Autowired
    private EduTeacherService teacherService;

    //查询前八条热门课程，前四个名师
    @GetMapping("index")
    public  R index(){

        QueryWrapper<EduCourse> courseQueryWrapper =new QueryWrapper<>();
        courseQueryWrapper.orderByDesc("view_count"); //降序
        courseQueryWrapper.last("limit 8");
        List<EduCourse> courseList = courseService.list(courseQueryWrapper);

        QueryWrapper<EduTeacher> teacherQueryWrapper =new QueryWrapper<>();
        teacherQueryWrapper.orderByDesc("id");//降序
        teacherQueryWrapper.last("limit 4");
        List<EduTeacher> teacherList = teacherService.list(teacherQueryWrapper);

        return R.ok().data("courseList",courseList).data("teacherList",teacherList);
    }

}
